package com.smit.adapter;

import java.util.ArrayList;
import java.util.List;

/**
 * DVB设备类
 */
public abstract class DVBDevice {
    /** 条形5.6.2.x */
    public static final String HW5_6_2 = "5.6.2";
    /** 条形5.6.3.x  */
    public static final String HW5_6_3 = "5.6.3";
    /** 墙内置  */
    public static final String HW5_6_6 = "5.6.6";
    /** 长方形 */
    public static final String HW5_6_7 = "5.6.7";

    /** 条形  */
    public static final int DEVICE_MODEL_OLD = 0;
    /** 长方形  */
    public static final int DEVICE_MODEL_SC01 = 1;
    /** 墙内置 */
    public static final int DEVICE_MODEL_86BOX01 = 2;

    /** 设备断开 */
    public static final int DVB_DEVICE_DISCONNECTED = 0;
    /** 设备连接上 */
    public static final int DVB_DEVICE_CONNECTED = 1;
    /** 设备出错 */
    public static final int DVB_DEVICE_ERROR = 2;
    /** 设备正在复位 */
    public static final int DVB_DEVICE_IS_RESETTING = 3;
    /** 设备复位完成 */
    public static final int DVB_DEVICE_HAS_RESET = 4;
    /** 设备初始化成功 */
    public static final int DVB_DEVICE_INIT_OK = 5;
    /** 设备初始化失败 */
    public static final int DVB_DEVICE_INIT_FAIL = 6;

    private static final String TAG = "DVBDevice";

    protected int status = 0;

    private List<IDVBDeviceCallback> deviceCallbackList = new ArrayList<IDVBDeviceCallback>();

    /**
     * 复位设备
     */
    public abstract void resetDevice();

    /**
     * 检测设备
     */
    public abstract void detectDevice();

    /**
     * 设备是否连接
     * @return true 连接， false 未连接
     */
    public abstract boolean isConnected();

    /**
     * 设置设备状态
     * @param status 参数如上 DVB_DEVICE_XX 状态
     */
    public void setStatus(int status) {
        this.status = status;
    }

    /**
     * 获取设备状态
     * @return 返回如上 DVB Device 状态
     * @see #DVB_DEVICE_CONNECTED
     * @see #DVB_DEVICE_DISCONNECTED
     * @see #DVB_DEVICE_ERROR
     * @see #DVB_DEVICE_HAS_RESET
     * @see #DVB_DEVICE_INIT_FAIL
     * @see #DVB_DEVICE_INIT_OK
     * @see #DVB_DEVICE_IS_RESETTING
     */
    public int getStatus() {
        return status;
    }


    /**
     * <p> 添加一个DVBDevice回调 <br/>
     * @param callback 回调接口
     */
    public void addCallback(IDVBDeviceCallback callback) {
        if (!deviceCallbackList.contains(callback)) {
            deviceCallbackList.add(callback);
        }
    }
    /**
     * <p> 移除一个DVBDevice回调 <br/>
     * @param callback 回调接口<br/>
     */
    public void removeCallback(IDVBDeviceCallback callback) {
        if (deviceCallbackList.contains(callback)) {
            deviceCallbackList.remove(callback);
        }
    }
    /**
     * <p> 获取所有DVBDevice回调对象 <br/>
     * @param 无
     * @return 返回所有注册进来的回调
     */
    public List<IDVBDeviceCallback> getCallbackList() {
        return deviceCallbackList;
    }

}